<div id="formDiv"></div>
<script type="text/html" id="shipmentOrderSignForm">
    <form lay-filter="SignFormContent" id="SignFormContent" class="layui-form open-form">
        <div class="open-model">
            <div class="open-auto">
                <div>
                    <table class="layui-table">
                        <thead>
                        <tr>
                            <th lay-data="{field:'shipmentOrderCode', width:150, sort: true, fixed: 'left'}">
                                发货记录编号
                            </th>

                            <th lay-data="{field:'materialName', width:150, sort: true, fixed: 'left'}">数据来源
                            </th>
                            <th lay-data="{field:'materialSpec', width:150, sort: true, fixed: 'left'}">所属合同编号</th>
                            <th lay-data="{field:'materialUnit', width:150, sort: true, fixed: 'left'}">客户代码</th>
                            <th lay-data="{field:'materialSpec', width:150, sort: true, fixed: 'left'}">
                                物料总净重
                            </th>
                            <th lay-data="{field:'materialSpec', width:150, sort: true, fixed: 'left'}">运单号</th>

                            <th lay-data="{field:'materialUnit', width:150, sort: true, fixed: 'left'}">车牌号</th>
                            <th lay-data="{field:'materialUnit', width:150, sort: true, fixed: 'left'}">司机</th>
                            <th lay-data="{field:'materialUnit', width:150, sort: true, fixed: 'left'}">司机电话</th>
                            <th lay-data="{field:'materialUnit', width:150, sort: true, fixed: 'left'}">状态
                            </th>
                            <th lay-data="{field:'materialUnit', width:150, sort: true, fixed: 'left'}">创建时间
                            </th>

                            <th lay-data="{field:'materialUnit', width:150, sort: true, fixed: 'left'}">创建人
                            </th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>

                            <td class="chooseCode">

                                <div  style="width: 100%;height: 100%;display: flex;align-items: center;justify-content: center;text-align: center"  id="shipmentOrderCode" ></div>
                                <div class="mask"></div>
                            </td>

                            <td>
                                <input class="layui-input adv-disable" id="source" disabled
                                       name="source"/>
                            </td>
                            <td>
                                <input type="text" class="layui-input" disabled id="contractCode"
                                       name="contractCode"/>
                            </td>
                            <td>
                                <input type="text" class="layui-input" disabled id="warehouseCustomerId"
                                       name="warehouseCustomerId"/>
                            </td>
                            <td>
                                <input class="layui-input adv-disable" id="totalWeight" disabled
                                       name="totalWeight"/>
                            </td>
                            <td>
                                <input class="layui-input adv-disable" id="waybill" disabled
                                       name="waybill"/>
                            </td>

                            <td>
                                <input type="text" class="layui-input" disabled name="plateNo"/>
                            </td>

                            <td>
                                <input type="text" class="layui-input" disabled name="driverName"/>
                            </td>
                            <td>
                                <input type="text" class="layui-input" disabled name="driverPhone"/>
                            </td>
                            <td>
                                <input type="text" class="layui-input" disabled name="shipmentOrderStatusName"/>
                            </td>
                            <td>
                                <input class="layui-input adv-disable" id="createTime" disabled name="createTime"/>
                            </td>
                            <td>
                                <input class="layui-input adv-disable" id="creatorName" disabled
                                       name="creatorName"/>
                            </td>

                        </tr>
                        </tbody>
                    </table>
                </div>
                <!--      <div class="layui-form-item tableContent">-->
                <!--        <table class="layui-table" id="signFormtable" lay-filter="signFormtable"></table>-->
                <!--      </div>-->
                <div class="layui-form-item tableContent" id="signC">
                    <table class="layui-table" id="signCheckFormTable" lay-filter="signCheckFormTable"></table>
                </div>
            </div>
            <div class="layui-form-item text-right">
                <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            </div>
        </div>
    </form>
</script>
<!--签收操作-->
<script>
    layui.use(["layer", "form", "table", "admin", "laydate", "upload", "laytpl"], async function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        let laydate = layui.laydate;
        let laytpl = layui.laytpl;
        const nowData = { ...parentData };
        let data = nowData?.data;
        let waybill = nowData?.waybill;
        let skuList = [];
        var formData={}
        var warehouseAreaList=[]
        const typeList=[
            {
                val:1,name:'普通物资'
            },{
                val:2,name:'加工预料'
            },{
                val:3,name:'加工原料'
            },{
                val:4,name:'加工成品'
            }
        ]
        const signQualifiedList=[
            {
                val:1,name:'合格'
            },{
                val:0,name:'不合格'
            }
        ]
        const statusList=[
            {val:1,name:'待签收'},
            {val:2,name:'已签收'},
            {val:3,name:'已入库'},
            {val:0,name:'已撤销'},
        ]

        laytpl(shipmentOrderSignForm.innerHTML).render(nowData, function (html) {
            $("#formDiv").after(html);
        });
        if (nowData.eventName === "detail") {
            admin.setFormDisable("#SignFormContent", true);
            form.render();
            $("#shipmentOrderCode").html(nowData.data.shipmentOrderCode);
        }

        const tableVal = table.render({
            elem: '#signCheckFormTable',
            page: false,
            limit: 999999,
            height: 240,
            data: [],
            cols: [[
                {type: "numbers", title: "序号"},
                {field: 'userBundleDetail', title: '客户捆包号', align: 'center'}
                , {field: 'productSpecCode', title: '规格码', align: 'center'}
                , {field: 'productMark', title: '钢种/牌号', align: 'center'}
                , {field: 'productProducer', title: '产地', align: 'center'}
                , {field: 'productVariety', title: '品种', align: 'center'}
                , {field: 'productUnit', title: '计量单位', align: 'center'}
                , {field: 'totalQuantity', title: '数量', align: 'center'}
                , {field: 'productWidth', title: '宽度', align: 'center'}
                , {field: 'productLength', title: '长度', align: 'center'}
                , {field: 'productThickness', title: '厚度', align: 'center'}
                , {
                    field: 'grossWeight', title: '毛重(吨)', align: 'center',
                }
                , {
                    field: 'netWeight', title: '净重(吨)', align: 'center',
                }
                , {
                    field: 'productType', title: '物资类型', align: 'center',
                    hide: nowData.eventName === "detail" ? false : true,
                    templet: admin.setTableSelect("productType",
                        typeList.map((v) => {
                            return {
                                label: v.name,
                                value: v.val
                            };
                        }), nowData.eventName === "detail", "productType")
                }, {
                    field: 'signQualified', title: '是否合格', align: 'center',
                    hide: nowData.eventName === "detail" ? true : false,
                    templet: admin.setTableSelect("signQualified",
                        signQualifiedList.map((v) => {
                            return {
                                label: v.name,
                                value: v.val
                            };
                        }), nowData.eventName === "detail", "signQualified")
                },{
                    field: 'warehouseAreaId', title: '库区', align: 'center',
                    hide: nowData.eventName === "detail" ? true : false,
                    templet: function (d) {
                        if (d.warehouseAreaList) {
                            return admin.setTableSelect(
                                "warehouseAreaId",
                                d.warehouseAreaList.map((v) => {
                                    return {
                                        label: v.name,
                                        value: v.id
                                    };
                                }),
                                nowData.eventName === "detail",
                                "warehouseAreaId"
                            )(d);
                        } else {
                            return "";
                        }
                    }
                }
                ,{
                    field: 'warehouseShelfSpaceId', title: '库位', align: 'center',
                    hide: nowData.eventName === "detail" ? true : false,
                    templet: function (d) {
                        if (d.codeList) {
                            return admin.setTableSelect(
                                "warehouseShelfSpaceId",
                                d.codeList.map((v) => {
                                    return {
                                        label: v.code,
                                        value: v.id
                                    };
                                }),
                                nowData.eventName === "detail",
                                "warehouseShelfSpaceId"
                            )(d);
                        }else{
                            return ''
                        }
                    }
                }
                , {
                    field: 'remarks', title: '备注', align: 'center',
                    templet: admin.setTableInput("remarks", nowData.eventName === "detail", "remarks")
                }
                // , {
                //     align: 'center',
                //     toolbar: '#signcheckFormTableBar',
                //     title: '操作',
                //     width: 100,
                //     fixed: 'right',
                //     hide: nowData.eventName === "detail" ? true : false
                // }
            ]],
            done: function (res, page, count) {

                $('.layui-table-header input[name="layTableCheckbox"]').prop('checked', true)
                $('.layui-table-header input[name="layTableCheckbox"]').next().addClass('layui-form-checked')
                res.data.forEach((element, index) => {
                    element["LAY_CHECKED"]='true'
                    $('tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);
                    $('tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked');
                });
                admin.tableInputChange("signCheckFormTable");
                admin.tableSelectChange("signCheckFormTable", 'signQualified');
                admin.tableSelectChange("signCheckFormTable", 'warehouseShelfSpaceId');
                admin.tableSelectChange("signCheckFormTable", "warehouseAreaId", (index, value, tableData, field) => {
                    admin.req(
                        "warehouse/warehouse/admin/warehouseFactoryShelfSpace/list",
                        {
                            warehouseAreaId: value
                        },
                        (res) => {
                            tableData[index].codeList = res.data;
                            table.reload("signCheckFormTable", {
                                data: tableData
                            });

                        }
                    );
                });
            },
        });

        if (data && data.id) {
            if(data.source==2){
                data.source='管理后台'
            }else if(data.source==1){
                data.source='客户端'
            }
            let info=statusList.filter(item=>item.val==data.shipmentOrderStatus)
            if(info.length){
                data.shipmentOrderStatusName=info[0].name
            }
            form.val("SignFormContent", data);
            tableVal.reload({
                data: data.orderInfoDetail.map((v) => {
                    v.eventName = "detail";
                    return v;
                })
            });
        } else {
        }

        $("#warehouseProductionOrderForm .layui-table-body").css("overflow", "visible");
        $("#warehouseProductionOrderForm .layui-table-box").css("overflow", "visible");
        $("#warehouseProductionOrderForm .layui-table-view").css("overflow", "visible");
    });
</script>

<style>
    #warehouseProductionOrderForm .layui-form-label {
        width: 125px;
    }

    #warehouseProductionOrderForm .layui-input-block {
        margin-left: 155px;
    }

    #warehouseProductionOrderForm .layui-form-item .layui-inline {
        /* margin-bottom: 5px; */
        margin-right: 0px;
    }

    #warehouseProductionOrderForm .layui-table-cell {
        overflow: visible !important;
    }

    .chooseCode {
        position: relative;
    }

    .mask {
        position: absolute;
        width: 100%;
        height: 100%;
        background: rgba(158, 157, 157, 0.1);
        top: 50%;
        left: 50%;
        z-index: 2;
        transform: translate(-50%, -50%);
    }
</style>